from django import forms


# 对ModelForm类的bootstrap样式继承类，以后所有带有input框的ModelForm表单均可以直接继承此类
class BootStrapModelForm(forms.ModelForm):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        for name, field in self.fields.items():
            if field.widget.attrs:
                field.widget.attrs['class'] = 'form-control'
            else:
                field.widget.attrs = {
                    'class': 'form-control',
                    'placeholder': field.label
                }


# 对Form类的bootstrap样式继承类，以后所有带有input框的Form表单均可以直接继承此类
class BootStrapForm(forms.Form):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        for name, field in self.fields.items():
            if field.widget.attrs:
                field.widget.attrs['class'] = 'form-control'
            else:
                field.widget.attrs = {
                    'class': 'form-control',
                    'placeholder': field.label
                }
